package com.example.pojo.dao;

import com.example.pojo.entity.Orders;
import com.example.pojo.entity.Resume;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//@Repository
@Transactional
public interface OrdersDao extends JpaRepository<Orders,Integer> {
    Orders findByOrdNumber(Long ordNum);

    @Modifying
    @Query(value = "update orders set ord_status = ?2 where ord_number=?1",nativeQuery = true)
    void updateOrdStatusByOrdNumber(Long ordNum,String newStatus);


    @Query(value = "select ord_status from orders where ord_number = ?1",nativeQuery = true)
    String findOrdStatusByOrdNumber(Long ordNum);

//    List<Orders> findByResuId(Integer resuId);

    List<Orders> findByOrdStatus(String ordStatus);

//    @Query(value = "select * from orders where js_id = ?1",nativeQuery = true)
    List<Orders> findByJsId(Integer jsId);

    @Query(value = "select * from orders where ord_title = ?1 and js_id = ?2",nativeQuery = true)
    List<Orders> findByOrdTitleAndJsId(String ordTitle,Integer jsId);

    @Query(value = "select * from orders where js_id = ?1 and resu_id = ?2",nativeQuery = true)
    List<Orders> findByResuIdAndJsId(Integer jsId,Integer resuId);

    @Query(value = "select * from orders where js_id=?1 and ord_status=?2",nativeQuery = true)
    List<Orders> findByOrdStatusAndId(Integer id,String ordStatus);
}
